package com.zrgj.ctrl;
import com.zrgj.entity.User1;

import com.zrgj.services.UserSrvImpl;
import com.zrgj.vo.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;

@RestController
public class UserCtrl {

    @Resource
    private UserSrvImpl userSrv;

    @RequestMapping("/user")
    public JsonResult query(User1 user) {
//        int i=1/0;
        JsonResult jr=new JsonResult(0,"ok");
        try {
            List list=userSrv.query(user);
            jr.setData(list);
        } catch (Exception throwables) {
            throwables.printStackTrace();
            jr.setCode(2);
            jr.setMsg("服务器发生错误！");
        }
        return jr;
    }

    @ExceptionHandler(RuntimeException.class)
    public JsonResult exceptionCtrl(Exception e) {
        JsonResult jr = new JsonResult(1, "用户模块发生错误，非常抱歉！");
        return jr;
    }

    @RequestMapping("/user2")
    public JsonResult query2(User1 user) throws FileNotFoundException {
        FileInputStream fis=new FileInputStream("sadsad");
        JsonResult jr=new JsonResult(0,"ok");
        try {
            List list=userSrv.query(user);
            jr.setData(list);
        } catch (Exception throwables) {
            throwables.printStackTrace();
            jr.setCode(2);
            jr.setMsg("服务器发生错误！");
        }
        return jr;
    }


}
